package com.ekuaitu.kuaitustaff.utils;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class Md5Utils {
    private static int BYTE_CACHE_SIZE = '저';
    private static ThreadLocal<MessageDigest> TL_DIGEST = new ThreadLocal();
    protected static final char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public Md5Utils() {
    }

    private static MessageDigest getDigest() throws NoSuchAlgorithmException {
        MessageDigest var0;
        if ((var0 = (MessageDigest) TL_DIGEST.get()) == null) {
            var0 = MessageDigest.getInstance("MD5");
            TL_DIGEST.set(var0);
        }

        return var0;
    }

    public static String getMD5(File file) {
        return getMD5(file, BYTE_CACHE_SIZE);
    }

    public static String getMD5(File file, int bufferSize) {
        FileInputStream var2 = null;
        boolean var9 = false;

        String file2;
        label99:
        {
            try {
                var9 = true;
                MessageDigest var3 = getDigest();
                var2 = new FileInputStream(file);
                byte[] file1 = new byte[bufferSize];

                while ((bufferSize = var2.read(file1)) != -1) {
                    var3.update(file1, 0, bufferSize);
                }

                file2 = bufferToHex(var3.digest());
                var9 = false;
                break label99;
            } catch (Exception var13) {
                var9 = false;
            } finally {
                if (var9) {
                    try {
                        if (var2 != null) {
                            var2.close();
                        }
                    } catch (IOException var10) {
                        ;
                    }

                }
            }

            try {
                if (var2 != null) {
                    var2.close();
                }
            } catch (IOException var11) {
                ;
            }

            return null;
        }

        try {
            var2.close();
        } catch (IOException var12) {
            ;
        }

        return file2;
    }

    public static String getMD5String(byte[] bytes) {
        try {
            getDigest().update(bytes);
            return bufferToHex(getDigest().digest());
        } catch (NoSuchAlgorithmException var1) {
            return null;
        }
    }

    public static String getMD5String(String s) throws NoSuchAlgorithmException {
        try {
            return getMD5String(s.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException var1) {
            return null;
        }
    }

    public static boolean checkPassword(String password, String md5PwdStr) throws NoSuchAlgorithmException {
        return getMD5String(password).equals(md5PwdStr);
    }

    private static String bufferToHex(byte[] bytes) {
        return bufferToHex(bytes, 0, bytes.length);
    }

    private static String bufferToHex(byte[] bytes, int m, int n) {
        StringBuffer var3 = new StringBuffer(2 * n);

        for (n += m; m < n; ++m) {
            appendHexPair(bytes[m], var3);
        }

        return var3.toString();
    }

    private static void appendHexPair(byte bt, StringBuffer stringbuffer) {
        char var2 = hexDigits[(bt & 240) >> 4];
        char bt1 = hexDigits[bt & 15];
        stringbuffer.append(var2);
        stringbuffer.append(bt1);
    }
}
